package com.zx.notification.admin.controller;

import com.zx.core.wrapper.ObjectWrapper;
import com.zx.core.wrapper.PageWrapper;
import com.zx.core.wrapper.ResponseWrapper;
import com.zx.log.annotation.OperateLog;
import com.zx.notification.admin.service.INotificationChannelsConfigService;
import com.zx.notification.common.param.NotificationChannelsConfigParam;
import com.zx.notification.common.vo.NotificationChannelsConfigVO;
import com.zx.validation.annotation.ParameterValidation;
import com.zx.validation.annotation.ParameterValidations;
import com.zx.validation.enums.ValidateRulesEnum;
import com.zx.validation.groups.Create;
import com.zx.validation.groups.StatusUpdate;
import com.zx.validation.groups.Update;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * description: 通知渠道配置管理控制器 <br>
 * create: 2025-10-17
 * </p>
 *
 * @author zhou  xun
 */
@RestController
@RequestMapping("/notification-channels-config")
@RequiredArgsConstructor
public class NotificationChannelsConfigController {

    private final INotificationChannelsConfigService iNotificationChannelsConfigService;

    /**
     * 分页查询通知渠道配置列表
     *
     * @param notificationChannelsConfigParam 查询参数
     * @return 通知渠道配置列表
     */
    @PreAuthorize("hasAuthority('notify:channel:list')")
    @PostMapping("/list")
    @ParameterValidations({
            @ParameterValidation(index = 0, desc = "通知渠道配置参数", rules = {ValidateRulesEnum.OBJECT}, groups = {com.zx.validation.groups.Query.class})
    })
    public PageWrapper<NotificationChannelsConfigVO> list(@RequestBody NotificationChannelsConfigParam notificationChannelsConfigParam) {
        return iNotificationChannelsConfigService.getNotificationChannelsConfigVOListByPage(notificationChannelsConfigParam);
    }

    /**
     * 新增通知渠道配置
     *
     * @param notificationChannelsConfigParam 通知渠道配置信息
     * @return {@link ResponseWrapper}
     */
    @OperateLog(value = "新增通知渠道配置")
    @PreAuthorize("hasAuthority('notify:channel:add')")
    @PostMapping("/addNotificationChannelsConfig")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "通知渠道配置参数", rules = {ValidateRulesEnum.OBJECT}, groups = {Create.class})
    )
    public ResponseWrapper addNotificationChannelsConfig(@RequestBody NotificationChannelsConfigParam notificationChannelsConfigParam) {
        return iNotificationChannelsConfigService.addNotificationChannelsConfig(notificationChannelsConfigParam);
    }

    /**
     * 编辑通知渠道配置
     *
     * @param notificationChannelsConfigParam 通知渠道配置信息
     * @return {@link ResponseWrapper}
     */
    @OperateLog(value = "编辑通知渠道配置")
    @PreAuthorize("hasAuthority('notify:channel:edit')")
    @PutMapping("/editNotificationChannelsConfig")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "通知渠道配置参数", rules = {ValidateRulesEnum.OBJECT}, groups = {Update.class})
    )
    public ResponseWrapper editNotificationChannelsConfig(@RequestBody NotificationChannelsConfigParam notificationChannelsConfigParam) {
        return iNotificationChannelsConfigService.editNotificationChannelsConfig(notificationChannelsConfigParam);
    }

    /**
     * 删除通知渠道配置
     *
     * @param notificationChannelsConfigId 通知渠道配置Id
     * @return {@link ResponseWrapper}
     */
    @OperateLog(value = "删除通知渠道配置")
    @PreAuthorize("hasAuthority('notify:channel:remove')")
    @DeleteMapping("/deleteNotificationChannelsConfig/{notificationChannelsConfigId}")
    @ParameterValidations({
            @ParameterValidation(index = 0, desc = "通知渠道配置Id", rules = {ValidateRulesEnum.NOT_NULL})
    })
    public ResponseWrapper deleteNotificationChannelsConfig(@PathVariable("notificationChannelsConfigId") String notificationChannelsConfigId) {
        return iNotificationChannelsConfigService.deleteNotificationChannelsConfig(notificationChannelsConfigId);
    }

    /**
     * 获取指定通知渠道配置信息
     *
     * @param notificationChannelsConfigId 通知渠道配置Id
     * @return 通知渠道配置信息
     */
    @OperateLog(value = "获取指定通知渠道配置信息")
    @PreAuthorize("hasAuthority('notify:channel:detail')")
    @GetMapping("/info/{notificationChannelsConfigId}")
    public ObjectWrapper<NotificationChannelsConfigVO> getNotificationChannelsConfigInfo(@PathVariable("notificationChannelsConfigId") String notificationChannelsConfigId) {
        return iNotificationChannelsConfigService.selectNotificationChannelsConfigById(notificationChannelsConfigId);
    }

    /**
     * 更新通知渠道配置状态
     *
     * @param notificationChannelsConfigParam 通知渠道配置参数
     * @return {@link ResponseWrapper}
     */
    @OperateLog(value = "更新通知渠道配置状态")
    @PreAuthorize("hasAuthority('notify:channel:edit')")
    @PutMapping("/updateNotificationChannelsConfigStatus")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "通知渠道配置参数", rules = {ValidateRulesEnum.OBJECT}, groups = {StatusUpdate.class})
    )
    public ResponseWrapper updateNotificationChannelsConfigStatus(@RequestBody NotificationChannelsConfigParam notificationChannelsConfigParam) {
        return iNotificationChannelsConfigService.updateNotificationChannelsConfigStatus(notificationChannelsConfigParam);
    }
}